﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Landscape.Business.FNH.Activities;

namespace Landscape.WebApp.Controls
{
    public partial class EmergencyFeedBack : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ICode"] != null && Request.QueryString["ICode"].Trim() != string.Empty)
                {
                    this.hfIncCode.Value = Request.QueryString["ICode"].Trim();

                    EmergencyActivities ea = new EmergencyActivities();
                    if (ea.GetIncidentByCode(Guid.Parse(Request.QueryString["ICode"].Trim())).IsClosed == true)
                        this.rbtnSave.Visible = false;
                }

                if (Request.QueryString["FBID"] != null && Request.QueryString["FBID"].Trim() != string.Empty)
                {
                    this.hfFbID.Value = Request.QueryString["FBID"].Trim();

                    EmergencyActivities ea = new EmergencyActivities();
                    var fb = ea.GetEmergencyFeedbackByID(Guid.Parse(Request.QueryString["FBID"].Trim()));

                    if (fb.Status == Business.FeedbackStatus.CLOSED)
                        this.rbtnSave.Visible = false;

                    foreach (ListItem item in this.rblFbType.Items)
                    {
                        if (item.Value == fb.Type.ToString())
                        {
                            item.Selected = true;
                            break;
                        }
                    }

                    this.rtbxComments.Text = fb.Comments;
                    this.rtbxCorrectiveAction.Text = fb.CorrectiveAction;

                    AdminActivities aa = new AdminActivities();

                    if (fb.AssignedTo != null)
                    {
                        this.rcbUsers.SelectedValue = fb.AssignedTo.ID.ToString();
                        //var ud = aa.GetUserMasterByID(fb.AssignedTo);
                        this.rcbUsers.Text = fb.AssignedTo.FirstName + " " + fb.AssignedTo.LastName;
                    }

                    if (fb.ReviewTo != null)
                    {
                        this.rcbReviewBy.SelectedValue = fb.ReviewTo.ID.ToString();
                        //var ud = aa.GetUserMasterByID(fb.ReviewTo);
                        this.rcbReviewBy.Text = fb.ReviewTo.FirstName + " " + fb.ReviewTo.LastName;
                    }

                    this.rdpExpectedDate.SelectedDate = fb.ResponseDueDate;
                    this.lblStatus.Text = fb.Status.ToString();

                    if (((Landscape.WebApp.UIBizObjects.ActiveUser)Session["ACTIVE_USER"]).UserID != fb.CreatedBy)
                    {
                        this.rbtnSave.Visible = false;
                    }

                    if (fb.Type == Business.FeedbackType.POSITIVES)
                    {
                        this.rdpExpectedDate.Enabled = false;
                        this.rcbUsers.Enabled = false;
                        this.rcbReviewBy.Enabled = false;
                        this.rtbxCorrectiveAction.Enabled = false;
                    }
                }
            }
        }
    }
}